package com.base.thread;

/**
 * 创建线程的第二种方法
 *
 * @author innocent
 * @date 2019/1/17 16:42
 */
public class RunnableThread implements Runnable {
    public int i;

    /**
     * run 核心业务方法，每个线程启动后，是只执行一次的。所以变量应该放在循环体内
     */
    @Override
    public void run() {

        System.out.println("---------" + Thread.currentThread().getName() + "进入运行状态---------");
        System.out.println("Do  Something...");
        /*while (i < 1000) {
            i++;
            System.out.println(Thread.currentThread().getName() + "\t" + i);
        }*/
        try {
            System.out.println("--------" + Thread.currentThread().getName() + "进入阻塞状态---------");
            Thread.sleep(5000);
            System.out.println("--------" + Thread.currentThread().getName() + "重新进入就绪状态---------");
            System.out.println("Continue Do ...");
            System.out.println("--------" + Thread.currentThread().getName() + "进入死亡状态---------");

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


    public static void main(String[] args) {
        Thread t1 = new Thread(new RunnableThread());
        t1.setName("线程1");
//        Thread t2 = new Thread(new RunnableThread());
//        t2.setName("线程2");
        MyThread t2 = new MyThread("线程2");


        t1.start();
        t2.start();
    }
}
